home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / program / swagd_f.zip / DIRS.SWG / 0015_Every Dir in Pascal.pas < prev    next >
Pascal/Delphi Source File  |  1993-08-27  |  1KB  |  51 lines

  1. {
  2. LAWRENCE JOHNSTONE
  3.  
  4. │Can someone give me some code (in TP) that recognizes all Sub-dirs
  5. │and Sub-sub-dirs, etc. in drive C and changes into every single one
  6. │of them one at a time?
  7. }
  8.  
  9. PROGRAM EveryDir;
  10.  
  11. USES
  12.   DOS
  13.  
  14. PROCEDURE ProcessDirs( Path: DOS.PathStr );
  15. VAR
  16.   SR : SearchRec;
  17. BEGIN
  18.   IF Path[Length(Path)] <> '\' THEN { Make sure last char is '\' }
  19.     Path := Path + '\';
  20.  
  21.   { Change to directory specified by Path.  Handle root as special case }
  22.   {$I-}
  23.   IF (Length(Path) = 3) AND (Copy(Path, 2, 2) = ':\') THEN
  24.     ChDir(Path)
  25.   ELSE
  26.     ChDir(Copy(Path, 1, Length(Path) - 1);
  27.   IF IOResult <> 0 THEN
  28.     EXIT; { Quit if we get a DOS error }
  29.   {$I-}
  30.  
  31.   { Process all subdirectories of that directory, except for }
  32.   { the '.' and '..' aliases                                 }
  33.   FindFirst(Path + '*.*', Directory, SR);
  34.   WHILE DosError = 0 DO
  35.   BEGIN
  36.     IF ((SR.Attr AND Directory) <> 0) AND
  37.         (SR.Name <> '.') AND (SR.Name <> '..') THEN
  38.       ProcessDirs( Path + SR.Name );
  39.     FindNext(SR);
  40.   END; { while }
  41. END; {ProcessDirs}
  42.  
  43. VAR
  44.   CurDir : DOS.PathStr;
  45.  
  46. BEGIN
  47.   GetDir(3, CurDir);  { Get default directory on C }
  48.   ProcessDirs('C:\'); { Process all directories on C }
  49.   ChDir(CurDir);      { Restore default directory on C }
  50. END.
  51.